<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\validate;

use think\Validate;

class PrizeValidate extends Validate
{

    protected $rule = [
        ['aid|活动', 'require'],
        ['sort|排序', 'require|number'],
        ['min_rank|最低名次', 'require|number|checkRank'],
        ['max_rank|最高名次', 'require|number'],
        ['rank_name|名称', 'require|length:1,20'],
        ['prize|奖品', 'require'],
    ];

    protected $scene = [
        'add'=>['title','sort','start_time','end_time','content'],
        'edit'=>['title','sort','start_time','end_time','content'],
    ];

    public function checkRank($value, $rule, $data){
        if($value > $data['max_rank']) {
            return '名次区间有误';
        } else {
            return true;
        }
    }



}
